package com.example.tbtx.tbtx;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.tbtx.tbtx.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class GuideActivity extends BaseActivity {


    @BindView(R.id.tv_pass)
    TextView tv_pass;
    public boolean isFinish=false;


    public int timeSecondCount = 3;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 0) {
                timeSecondCount--;
                if (timeSecondCount < 1&& !isFinish) {
                    startActivity(new Intent(GuideActivity.this, SpaceActivity.class));
                    finish();
                    return;
                }
                if (tv_pass!=null)
                tv_pass.setText(String.format("%dS 跳过",timeSecondCount));
                Log.d("fssssssss", "handleMessage: ");
                if (!isFinish)
                handler.sendEmptyMessageDelayed(0, 1000);
            }
        }
    };

    @Override
    public int setLayout() {
        return R.layout.activity_guide;
    }

    @Override
    public void initEvent() {
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        handler.sendEmptyMessageDelayed(0, 1000);


    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public void initData() {

    }

    @OnClick({R.id.tv_pass})
    public void onClick(View view){
        handler.removeMessages(0);
        isFinish=true;
        startActivity(new Intent(GuideActivity.this, SpaceActivity.class));
        finish();
    }

}
